from PyQt5.QtCore import QThread, pyqtSignal, QDateTime, QTimer
from PyQt5.QtWidgets import QApplication, QDialog, QLineEdit
import time
import sys
import datetime
import asyncio


class Window(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        self.setWindowTitle("PyQt 5界面实时更新例子")
        self.resize(400, 500)
        self.input = QLineEdit(self)
        self.input1 = QLineEdit(self)
        self.input.resize(400, 100)
        self.input1.resize(400, 100)
        self.input1.move(0, 100)
        self.initUI()

    def initUI(self):
        # Create a timer to update the display every second
        self.timer = QTimer()
        self.timer.timeout.connect(self.handleDisplay)
        self.timer.start(1000)  # Update every 1000ms (1 second)
        self.handleDisplay()  # Initial update

    # 将当前时间输出到文本框
    def handleDisplay(self):
        data = QDateTime.currentDateTime()
        currTime = data.toString("yyyy-MM-dd hh:mm:ss")
        print(currTime)
        self.input.setText(currTime)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec_())
